package easyzhou.com.ui;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class CenterPanel extends JPanel {
	private JFrame parent;
	private JTextArea textArea;

	/**
		 * 
		 */
	private static final long serialVersionUID = 7016818519916805795L;

	private CenterPanel(JFrame parent) {
		this.parent = parent;
	}

	public void init() {
		textArea = new JTextArea();
		setBackground(Color.GRAY); // 将JPanel的实例背景设置为黄色
		GridBagLayout gridLayout = new GridBagLayout();
		setLayout(gridLayout);
		add(textArea);
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		// 是用来控制添加进的组件的显示位置
		gridBagConstraints.fill = gridBagConstraints.BOTH;
		{
			gridBagConstraints.insets = new Insets(1, 1, 1, 1);
			gridBagConstraints.gridwidth = 1;// 该方法是设置组件水平所占用的格子数，如果为0，就说明该组件是该行的最后一个
			gridBagConstraints.weightx = 1;// 第一列的分布方式为10%
			gridBagConstraints.weighty = 1;// 该方法设置组件垂直的拉伸幅度，如果为0就说明不拉伸，不为0就随着窗口增大进行拉伸，0到1之间
			gridLayout.setConstraints(textArea, gridBagConstraints);// 设置组件
		}

	}

	public String getCenterTextAreaText() {
		return this.textArea.getText();
	}

	public void setCenterTextAreaText(String str) {
		this.textArea.setText(str);
	}

	@Override
	public String toString() {
		return "CenterPanel [parent=" + parent + ", textArea=" + textArea + "]";
	}

	public static final CenterPanel newInstance(JFrame frame) {
		CenterPanel panel = new CenterPanel(frame); // 创建一个JPanel的实例
		panel.init();
		return panel;
	}
}
